//
//  VideoLoadHUD.m
//  FunnyVideo
//
//  Created by 李鑫 on 15/9/3.
//  Copyright © 2015年 NewEggTech. All rights reserved.
//


#define HUDWH 50
#define HUDImageName @"PlayerTimeline-Icon-LoadingView"
#import "VideoLoadHUD.h"
#import "PullToReact.h"


@interface VideoLoadHUD ()

@property (nonatomic,strong) UIActivityIndicatorView *circleView;
@property (nonatomic,strong) NSTimer     *animationTimer;
@property (nonatomic,assign) CGFloat     r_angle;
@end
@implementation VideoLoadHUD


+ (VideoLoadHUD *)sharedManger{
    static dispatch_once_t onceToken;
    static VideoLoadHUD    *HUD;
    dispatch_once(&onceToken, ^{
        HUD = [[VideoLoadHUD alloc] init];
    });
    
    return HUD;
}

- (id)init{
    self = [super init];
    
    if(self)
    {
        self.r_angle = 0;
        
        self.circleView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
        self.circleView.hidesWhenStopped = NO;
        [self.circleView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
        [self.circleView setBackgroundColor:AdornColor];
    }
    
    return self;
}

- (void)makeCircleRotate{
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.circleView startAnimating];
    });

}

- (void)stopCircleRotate{
    dispatch_async(dispatch_get_main_queue(), ^{
            [self.circleView stopAnimating];
    });

}

+ (void)showIn:(UIView *)view{
    //Add
    [VideoLoadHUD sharedManger].circleView.center = view.center;
    [view addSubview:[[VideoLoadHUD sharedManger] circleView]];
    //Make Animation
    [UIView animateWithDuration:0.8 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:0.8 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        UIActivityIndicatorView *HUD = [[VideoLoadHUD sharedManger] circleView];
        HUD.transform = CGAffineTransformMakeScale(1, 1) ;
    } completion:^(BOOL finished) {
        VideoLoadHUD *HUD = [VideoLoadHUD sharedManger];
        [HUD makeCircleRotate];
    }];
}
+ (void)dismiss{
    [UIView animateWithDuration:0.8 delay:0 usingSpringWithDamping:0.5 initialSpringVelocity:0.8 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        UIActivityIndicatorView *HUD = [[VideoLoadHUD sharedManger] circleView];
        HUD.transform = CGAffineTransformMakeScale(0, 0) ;
    } completion:^(BOOL finished) {
        UIActivityIndicatorView *HUD = [[VideoLoadHUD sharedManger] circleView];
        [[VideoLoadHUD sharedManger] stopCircleRotate];
        [HUD removeFromSuperview];
    }];
}
@end
